using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using YY.Basic.DB;
using YY.Basic;
using System.Collections;
namespace TK3DSim.Mil
{
    public class ArmKinds : TableRelateObj
    {
        public ArmKinds()
            : base(Global.Instance.DB, "TAllShow", "ID")
        {

        }

        //��Ч�ܺ�
        /// </summary>
        public int Count
        {
            get { return this.Table.Rows.Count; }
        }

        /// <summary>
        /// ���һ���µ�����װ������
        /// </summary>
        /// <param name="name">�������</param>
        /// <returns></returns>
        public ArmKind Add(ShowWhat showwhat, string weponid, OwnerKinds showkind, string filename, string x, string y, string z, string scal, string animalspped,string name)
        {

            DataRow row = this.Table.NewRow();

            row["ID"] = System.Guid.NewGuid().ToString();
            row["Name"] = name;
            row["ShowWhat"] = showwhat;
            row["ArgumentID"] = weponid;
            row["ShowKind"] = showkind;
            row["Filename"] = filename;
            row["Scal"] = scal;
            row["x"] = x;
            row["y"] = y;
            row["z"] = z;
            row["AnimalSpeed"] = animalspped;

            this.Table.Rows.Add(row);

            bool res = this.UpdateData();

            if (res)
            {
                return new ArmKind(row);
            }
            else
            {
                throw new Exception("��Ч�����ʧ��");
            }
        }

        public void DelteWeapon(string weponid)
        {
            DataRow[] rows = this.Table.Select("ArgumentID='" + weponid + "'");
            for (int i = 0; i < rows.Length; i++)
            {
                rows[i].Delete();
            }
            this.UpdateData();
        }

        public ArrayList ListWeapon(string weponid)
        {
            ArrayList items = new ArrayList();
            DataRow[] rows = this.Table.Select("ArgumentID='" + weponid + "'");
            for (int i = 0; i < rows.Length; i++)
            {
                items.Add(new ArmKind(rows[i]));
            }
            return items;
        }

        public bool Exist(string ID)
        {
            DataRow[] rows = this.Table.Select("ID='" + ID + "'");
            if (rows.Length <= 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        internal void DeleteCurrentID(string weaponid, string filename, OwnerKinds ownerKinds)
        {
            string rr = "ArgumentID='" + weaponid + "' and ShowKind=" + (int)ownerKinds + "  and  Filename='" + filename + "'";
            DataRow[] rowset = this.Table.Select(rr);
            if (rowset.Length == 0)
            {
                return;
            }
            for (int i = 0; i < rowset.Length; i++)
            {
                rowset[i].Delete();
            }
            this.UpdateData();
        }



        internal string FindBy(string wepond, object Name, ShowWhat showKinds)
        {
            string rr = "ArgumentID='" + wepond + "' and ShowWhat=" + (int)showKinds + "  and  Name='" + Name + "'";
            DataRow[] rowset = this.Table.Select(rr);
            if (rowset.Length == 0)
            {
                return null;
            }
            else
            {

                ArmKind f = new ArmKind(rowset[0]);
                return f.ID;

            }
        }


        internal List<ArmKind> FindbyEq(string equpument)
        {
            List<ArmKind> lak = new List<ArmKind>();
            string rr = "ArgumentID='" + equpument + "' ";
            DataRow[] rowset = this.Table.Select(rr);
            if (rowset.Length > 0)
            {
                for (int i = 0; i < rowset.Length; i++)
                {
                    lak.Add(new ArmKind(rowset[i]));
                }
            }
            return lak;

        }
    }
}
